<?php
$yhendus=new mysqli("localhost", "juku", "kala", "jukubaas2");
if(isSet($_REQUEST["uusleht"])){
$kask=$yhendus->prepare("INSERT INTO lehed (pealkiri, sisu) VALUES (?, ?)");
$kask->bind_param("ss", $_REQUEST["pealkiri"], $_REQUEST["sisu"]);
$kask->execute();
header("Location: $_SERVER[PHP_SELF]");
$yhendus->close();
exit();
}
?>
<!doctype html>
<html>
<head>
<!---->
<title>Ifikate rebaste ristimine 2013</title>
<meta charset="UTF-8"> 
<base target="_blank"> 
</head>
<body>
<div id="menyykiht">
<h2>Registreerimine</h2>
<ul>
<?php
$kask=$yhendus->prepare("SELECT id, pealkiri FROM registreerimine");
$kask->bind_result($id, $pealkiri);
$kask->execute();
while($kask->fetch()){
echo "<li><a href='?id=$id'>".
htmlspecialchars($pealkiri)."</a></li>";
}
?>
<a href='regamiselink'></a>
</div>
<div id="sisukiht">
<?php
if(isSet($_REQUEST["id"])){
$kask=$yhendus->prepare("SELECT id, pealkiri, sisu FROM registreerimine");
$kask->bind_param("i", $_REQUEST["id"]);
$kask->bind_result($id, $pealkiri, $sisu);
$kask->execute();
if($kask->fetch()){
echo "<h2>".htmlspecialchars($pealkiri)."</h2>";
echo htmlspecialchars($sisu);
}
}
if(isSet($_REQUEST["lisamine"])){
?>
<form action='?'>
<dl>
<dt>Aasta:</dt>
<dd>
<input type="text" name="pealkiri" />
</dd>
<dt>Nimi:</dt>
<dd>
<textarea rows="20" name="sisu"></textarea>
</dd>
</dl>
<input type="submit" value="sisesta">
</form>
<?php
}
?>
</div>
<div id="jalusekiht">
Lehe tegi xxx
</div>
</body>
</html>
<?php
$yhendus->close();
?>